//
//  DFSegementView.swift
//  DailyFresh
//
//  Created by Arthur on 2017/9/20.
//  Copyright © 2017年 DailyFresh. All rights reserved.
//

import UIKit
import SnapKit

class DFSegmentView: UIView {
    
    var titles: [String]
    var style: DFSegmentStyle
    var childViewControllers: [UIViewController]
    var parentViewController: UIViewController
    
    init(frame: CGRect,style: DFSegmentStyle, titles: [String], childViewControllers: [UIViewController], parentViewController: UIViewController) {
        self.titles = titles
        self.style = style
        self.childViewControllers = childViewControllers
        self.parentViewController = parentViewController
        super.init(frame: frame)
        self._setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func _setupUI() {
        let titleViewFrame = CGRect(x: 0, y: 0, width: DFLayoutConstants.screenWidth, height: self.style.titleViewHeight)
        let titleView = DFSegmentTitleView(frame: titleViewFrame, titles: self.titles, style: self.style)
        titleView.backgroundColor = UIColor.white
        self.addSubview(titleView)
        //2.创建内容View
        let contentFrame = CGRect(x: 0, y: titleView.frame.maxY, width: bounds.width, height: bounds.height - titleView.frame.maxY)
        let contentView = DFSegmentContentView(frame: CGRect.zero, childVcs: childViewControllers, parentVc: parentViewController, style: style)
        contentView.backgroundColor = UIColor.blue
        self.addSubview(contentView)
        //3.设置代理对象
        titleView.delegate = contentView
        contentView.delegate = titleView
        
        titleView.snp.makeConstraints { (make) in
            make.height.equalTo(self.style.titleViewHeight)
            make.top.equalTo(0)
            make.left.equalTo(0)
            make.right.equalTo(0)
        }
        
        contentView.snp.makeConstraints { (make) in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(self.style.titleViewHeight, 0, 0, 0))
        }
    }
    
    
}

//// MARK: - Lazy load properties
//extension DFSegementView {
//    lazy var titleView = {
//        [unowned self] in
//        let tmp =
//    }()
//}

